import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.methods.GetMethod;

public class TestDownload {

//	private final static String REMOTE_FILE_URL = "http://mp3.baidu.com/j?j=2&url=http%3A%2F%2Fzhangmenshiting2.baidu.com%2Fdata%2Fmusic%2F2010157%2F%25E7%259F%25A5%25E8%25B6%25B3.mp3%3Fxcode%3Db78743a816383ea860279f6048119845";
	private static String DownLoadAddress = "http://mp3.baidu.com/m?lm=-1&f=ms&tn=baidump3&ct=134217728&lf=&rn=&word=god+is++a+girl";
	
	private final static int BUFFER = 1024;

	public static void main(String[] args) {

		HttpClient client = new HttpClient();
		GetMethod httpGet = new GetMethod(DownLoadAddress);
		try {
			client.executeMethod(httpGet);

			InputStream in = httpGet.getResponseBodyAsStream();

			FileOutputStream out = new FileOutputStream(new File(
					"E:\\TestDownload.mp3"));

			byte[] b = new byte[BUFFER];
			int len = 0;
			while ((len = in.read(b)) != -1) {
				out.write(b, 0, len);
			}
			in.close();
			out.close();

		} catch (HttpException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			httpGet.releaseConnection();
		}
		System.out.println("download, success!!");
	}
}